package com.wangjiyuan.shiwupai.ui.activity.photo;

import com.wangjiyuan.shiwupai.bean.guangchi.photo.PhotoBean;

import rx.Subscriber;
import rx.Subscription;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by wjy on 2016/12/1.
 */

public class PhotoPresenter implements PhotoContract.PhotoPresenter {
    private PhotoContract.PhotoView mView;
    private PhotoContract.PhotoModel mModel;
    private Subscription subscribe;

    public PhotoPresenter(PhotoContract.PhotoView view) {
        mView = view;
        mModel = new PhotoModel();
    }

    @Override
    public void getPhoto(String id) {
        subscribe = mModel.getPhoto(id).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<PhotoBean>() {
                    @Override
                    public void onCompleted() {
                        subscribe.unsubscribe();
                    }

                    @Override
                    public void onError(Throwable e) {
                        subscribe.unsubscribe();
                    }

                    @Override
                    public void onNext(PhotoBean bean) {
                        mView.getPhoto(bean);
                    }
                });
    }
}
